package com.fire.control.system.module.device.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fire.control.system.dto.SelectDeviceGroupDTO;
import com.fire.control.system.entity.DeviceGroup;
import com.fire.control.system.module.device.dao.DeviceGroupMapper;
import com.fire.control.system.module.device.service.DeviceGroupService;

@Service
public class DeviceGroupServiceImpl implements DeviceGroupService{
	
	@Autowired private DeviceGroupMapper deviceGroupMapper;
	
	
	/**
	 * @author: xiechengguang 
	 * @Title: getSelectDeviceGroupList   
	 * @Description: TODO  
	 * @param:        
	 * @return: List<SelectDeviceGroupDTO>      
	 * @throws
	 */
	public List<SelectDeviceGroupDTO> getSelectDeviceGroupList(String companyId){
		List<DeviceGroup> groupList = deviceGroupMapper.getAllGroups();
		List<SelectDeviceGroupDTO> groupDtos = new ArrayList<SelectDeviceGroupDTO>();
		List<SelectDeviceGroupDTO> dto = deviceGroupMapper.getDeviceGroups(companyId);
		groupDtos.addAll(dto);
		getSelectDeviceGroupList(groupDtos, groupList, companyId);
		return groupDtos;
	}
	
	/**
	 * @author: xiechengguang 
	 * @Title: getSelectDeviceGroupList   
	 * @Description: TODO  
	 * @param:        
	 * @return: void      
	 * @throws
	 */
	private void getSelectDeviceGroupList(List<SelectDeviceGroupDTO> groupDtos, List<DeviceGroup> groupList, String pid){
		for (DeviceGroup deviceGroup : groupList) {
			String id = deviceGroup.getId();
			String parentId = deviceGroup.getParentId();
			if(pid.equals(parentId)){
				List<SelectDeviceGroupDTO> dto = deviceGroupMapper.getDeviceGroups(id);
				groupDtos.addAll(dto);
				getSelectDeviceGroupList(groupDtos,groupList,id);
			}
		}
	}
	
}
